package com.bdqn.service.impl;

import com.bdqn.dao.UserDao;
import com.bdqn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/*<bean id="userService" class="com.bdqn.service.impl.UserSavriceImpl">*/
/*@Component("userSavrice")*/
@Service("userService")
//@Scope("prototype")//多例
@Scope("singleton")//单例
public class UserSavriceImpl implements UserService {
    @Value("张三") //普通数据类型注入
    private String name;
    @Value("${jdbc.driver}")//从容器中找到key jdbc.driver 对应的值并注入
    private String driver;


    /* <property name="userDao" ref="userDao"></property>*/
    // @Autowired//按照数据类型从容器中进行匹配
    //  @Qualifier("userDao")//按照id从容器中进行匹配，需要@Autowired配合使用。用此注解可以省略set方法
    @Resource(name = "userDao")//相当于@Autowired+ @Qualifier
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public void save() {
        userDao.save();
        System.out.println(name);
        System.out.println(driver);
    }

    @PostConstruct//初始方法

    private void init(){
        System.out.println("初始化方法");
    }
}
